package com.zyf.school.manager.service.impl;

import com.zyf.school.manager.dao.DictTreeDao;
import com.zyf.school.manager.domain.DictTree;
import com.zyf.school.manager.service.DictTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DictTreeServiceImpl implements DictTreeService {
    @Autowired
    DictTreeDao dictTreeDao;

    List<DictTree> list = null;

    @Override
    public List<DictTree> queryDictTree(int parentId) {
        list = dictTreeDao.queryParent();
        list = this.tree(list);
        return list;
    }
    //遍历
    public List<DictTree> tree(List<DictTree> tree){
        if(tree.size()>0){
            for(int i=0; i<tree.size(); i++){
                int id = tree.get(i).getId();
                list = dictTreeDao.queryByParentId(id);
                if (list.size()>0){
                    tree.get(i).setChildren(list);
                    tree(list);
                }
            }
        }
        return tree;
    }
}
